#ifndef _K_LINKARRAY_
#define	_K_LINKARRAY_

namespace krt
{
	class KRUNTIME_CLASS LinkArray
	{
	private:
		class LinkNode
		{
		private:
			size_t m_nPrev;
			size_t	m_nNext;
		public:
			LinkNode(): m_nPrev(0), m_nNext(0){}
			inline size_t GetPrev(){return m_nPrev;}
			inline size_t GetNext() {return m_nNext;}
			inline void SetPrev(int nPrev){m_nPrev = nPrev;}
			inline void SetNext(int nNext) {m_nNext = nNext;}
		};

		LinkNode*	m_pNode;
		size_t m_nCount;
	public:
		inline LinkArray(): m_pNode(NULL), m_nCount(0) {}
		~LinkArray();
		inline size_t GetCount() { return m_nCount; }
		inline LinkNode* GetNode(int nIdx){return &m_pNode[nIdx];};

		inline size_t GetNext(int nIdx) const 
		{ 
			if(m_pNode) 
				return m_pNode[nIdx].GetNext(); 
			else 
				return 0;
		}

		inline size_t GetPrev(int nIdx) const 
		{ 
			if(m_pNode) return m_pNode[nIdx].GetPrev(); 
			else return 0;
		}

		void  init(size_t nSize);
		void  remove(size_t nIdx);
		void  insert(size_t nIdx);
	};
}

#endif //_K_LINKARRAY_
